package xxdsqljobDB

import com.alibaba.fastjson.JSONObject

import java.text.SimpleDateFormat

/**
 * Created by Administrator on 2019-08-05.
 */
class Job2ReportModel {
    String TITLE
    String JOB_NAME
    String SQL_IDS
    String PARAM
    String UPLOAD_PATH


    public getPhysicalFile( ){
        def dowLoadPath = new File("${this.UPLOAD_PATH}${File.separator}${new Date().format("yyyy-MM-dd")}")
        if(!dowLoadPath.exists() ){
            dowLoadPath.mkdirs()
            println "Dir was created!...."
        }
        def path = "${dowLoadPath.absolutePath}${File.separator}${this.getFileName()}"
        return  String.valueOf(path)
    }
    public getFileName(){
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMdd.HHmmss.S")
        Date date = new Date()
        def fileName = "${this.TITLE}.${this.JOB_NAME}.${ simpleDateFormat.format(date)}.xlsx"
        return fileName
    }
    public getSqlList(){

        def list = []
        if(this.SQL_IDS){
            def sqlIds = this.SQL_IDS.replace("；",";").replace(" ","")
            list = sqlIds.split(";").toList().unique()
        }
        return list
    }
    public getParamMap(){
        if(this.PARAM){
            return JSONObject.parseObject(this.PARAM)
        }
        return [:]
    }
}
